<template>
  
	<view class="page">
		<fu-custom :isBack="true" :isBottom="true" bgColor="bg-white">
			<view slot="content">{{i18n["历史反馈"]}}</view>
		</fu-custom>
		<!-- 数据加载动画 start -->
		<fu-loading v-if="isShowLoading"></fu-loading>
		<!-- 数据加载动画 end -->
		<block v-else>
			<!-- 反馈列表 start -->
			<view class="padding-lr">
				<view class="padding-tb solid-bottom" v-for="(item, index) in list" :key="index">
					<view class="flex align-stretch">
						<view class="fu-block-72 margin-right-sm">
							<fu-image :src="userInfo.head_img" radius="72" mode="aspectFill"></fu-image>
						</view>
						<view class="flex-sub" style="min-width: 1px;">
							<view class="margin-bottom flex">
								<view class="write-content text-333 fu-fs28 line-height-46 relative"
									:class="[ (item.isMoreLine && item.isOpent) ? '' : 'text-cut-2']"
									:id="'content-desc-' + item.id ">
									<!-- <view class="" style="width: 590rpx;">
										{{item.body}}
									</view> -->
									<rich-text style="width: 590rpx;" :nodes="item.body"></rich-text>
									<view
										class="direction-position radius-4 bg-white fu-block-32 flex align-center justify-center line-theme solid text-theme"
										v-if="item.isMoreLine" @click="hanldeOpenOrClose(item)">
										<text v-if="item.isOpent" class="cuIcon-fold"></text>
										<text v-else class="cuIcon-unfold"></text>
									</view>
								</view>
							</view>
							<view class="grid col-3 grid-square" v-if="item.thumb.length">
								<view v-for="(imgItem, imgIndex) in item.thumb" :key="imgIndex">
									<view class="fu-block-180" @tap="ViewImage(item.thumb, imgIndex)">
										<fu-image radius="12" :src="imgItem" mode="aspectFill"></fu-image>
									</view>
								</view>
							</view>
							<!-- <view class="text-999 fu-fs24">
								{{i18n['联系方式']}}:
								<text class="margin-left-sm">{{item.contact || '无'}}</text>
							</view> -->
							<view class="text-999 fu-fs24 margin-top-sm">
								{{i18n['反馈类型']}}:
								<text class="margin-left-sm">{{item.type || i18n['无']}}</text>
							</view>
							<view class="text-999 fu-fs24 margin-top-sm">
								{{i18n['反馈时间']}}:
								<text class="margin-left-sm">{{item.create_time | formatDate('YYYY-MM-DD')}}</text>
							</view>
							<view class="padding-sm bg-f6 margin-top-sm fu-fs28" v-if="item.replay">
								<text class="" style="color: #59A6F4;">{{i18n['平台回复']}}: </text>
								<text class="text-333">{{item.replay}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 反馈列表 end -->
			<!-- 无数据 start -->
			<view v-if="isInitEnd"
				class="text-xl text-center text-gray flex flex-direction align-center justify-center">
				<image :src="imgBaseUrl + 'empty/message.png'" mode="widthFix" style="width:400rpx;"></image>
				<text class="margin-top text-df">{{i18n['暂无反馈内容']}}</text>
			</view>
			<!-- 无数据 end -->
		</block>
		<!-- 断网监测 start -->
		<fu-notwork></fu-notwork>
		<!-- 断网监测 end -->

	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShowLoading: false, //数据加载动画
				isInitEnd: false, //  数据为空true
				list: [], //列表数据
				isOpent: true,
			}
		},
		computed: {
			userInfo() {
				return this.$store.getters.userInfo;
			}
		},
		onLoad() {
			// 获取反馈数据
			this.get_list();
		},
		methods: {
			hanldeOpenOrClose(item) {
				item.isOpent = !item.isOpent
				this.$forceUpdate()
			},
			// 计算位置
			computedPos() {
				const query = uni.createSelectorQuery().in(this);
				this.list.forEach((item, index) => {
					query.select('#content-desc-' + item.id).boundingClientRect(data => {
						item.height = data.height
						console.log(data.height, 'data.height');
						if (data.height > 40) {
							item.isMoreLine = true //是否为多行
							item.isOpent = false //是否显示更多
						} else {
							item.isMoreLine = false
							item.isOpent = true
						}
						this.$forceUpdate();
					}).exec();
				})
			},
			/**
			 * @description 获取反馈数据
			 */
			get_list() {
				let that = this
				// 开启数据加载动画
				this.isShowLoading = true;
				this.$api.get(global.apiUrls.myFeedback).then(res => {
					if (res.data.code == 1) {
						this.list = JSON.parse(JSON.stringify(res.data.data));
						// 数据为空时显示空状态
						if (res.data.data.length == 0) {
							this.isInitEnd = true;
						} else {
							this.list.forEach(item => {
								item.isMoreLine = false
								item.isOpent = true
							})
							setTimeout(function() {
								that.$nextTick(() => {
									that.computedPos();
								});
							}, 0)
						}
					} else {
						// 数据为空
						this.isInitEnd = true;
						// 数据加载失败提示
						this.$message.info(res.data.msg);
					}
					// 关闭数据加载动画
					this.isShowLoading = false;
				}).catch(err => {
					// 数据加载失败
					this.isInitEnd = true;
					// 关闭数据加载动画
					this.isShowLoading = false;
				});
			},
			/**
			 * @description 预览图片
			 * @param {Object} list 图片数组
			 * @param {String} index 当前图片链接
			 */
			ViewImage(list, index) {
				uni.previewImage({
					urls: list,
					current: index
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		// height: 100%;
		min-height: 100vh;
		background: white !important;

		.write-content {
			.direction-position {
				position: absolute;
				right: 5rpx;
				bottom: 5rpx;
			}
		}

	}
</style>
